﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DreamCMS.WebCore.Common;
using DreamCMS.BLL;
using DreamCMS.Entity.Common;
using DreamCMS.Entity;

namespace DreamCMS.Web
{
    public partial class Default : FrontPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            InitCurrentTemplateContext();//初始化当前页面的模板标签上下文对象
            Display("default.html"); //展现页面
        }
     
        /// <summary>
        /// 初始化模板引擎辅助类
        /// 使用相关标签数据初始化模板辅助类中的NVelocity模板的标签上下文对象
        /// </summary>
        private void InitCurrentTemplateContext()
        {
            tplHelper.Put(DmTagsSet.PAGE_TITLE, "首页"); //设置模板页面的title标题
            tplHelper.Put(DmTagsSet.IS_DEFAULT, "1");  //设置首页标识标签，用于在模板中进行首页判断
            tplHelper.Put(DmTagsSet.POST_MESSAGE, string.Empty); //页面信息，比如可以显示当前页面的Position,显示当前页面是搜索结果页，或者标签列表页或者作者文章列表页

            //文章页列表（首页）
            int categoryId = -1;
            int tagId = -1;
            int userId = -1;
            string keyword = string.Empty;
            string data = string.Empty;
            string begindate = string.Empty;
            string enddate = string.Empty;
            long recordCount = 0;
            long pageindex = RequestHelper.QueryInt("page", 1); //获取页码
            string pageUrl = RequestHelper.SiteUrl + "default.aspx?page={0}";

            tplHelper.Put(DmTagsSet.POSTS, PostManager.GetPostList(SiteSettingManager.GetSiteSettingInfo().PageSizePostCount, pageindex, out recordCount, categoryId, tagId, userId, PostRecommend.Other,PostStatus.Published,PostTopStatus.Other, PostHideStatus.NoHide, begindate, enddate, keyword));
            string pageHtml = Pager.CreateHtml(SiteSettingManager.GetSiteSettingInfo().PageSizePostCount, recordCount, pageUrl);
            tplHelper.Put(DmTagsSet.PAGER, pageHtml);
        }
    }
}